using System;
using System.Linq.Expressions;

namespace DuplexTransformers
{
    public class PropertyRelationshipTransformerExpression<TLeft, TRight, TLeftProp, TRightProp>
    {
        private readonly Action<PropertyRelationship<TLeft, TRight, TLeftProp, TRightProp>> _propertyMapConsumer;
        private readonly Expression<Func<TLeft, TLeftProp>> _leftExpression;
        private readonly ITransformer<TLeftProp, TRightProp> _transformer;

        public PropertyRelationshipTransformerExpression(Action<PropertyRelationship<TLeft, TRight, TLeftProp, TRightProp>> propertyMapConsumer, Expression<Func<TLeft, TLeftProp>> leftExpression, ITransformer<TLeftProp, TRightProp> transformer)
        {
            _propertyMapConsumer = propertyMapConsumer;
            _leftExpression = leftExpression;
            _transformer = transformer;
        }

        public void MapsTo(Expression<Func<TRight, TRightProp>> expr)
        {
            var propertyMap = new PropertyRelationship<TLeft, TRight, TLeftProp, TRightProp>(
                _leftExpression, _transformer, expr);
            _propertyMapConsumer(propertyMap);
        }
    }
}